package com.mzx.servlet;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


public class HelloServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1.接收前端传过来的参数
        String method=req.getParameter("method");
        if (method.equals("add")){
            req.getSession().setAttribute("msg","执行了add的方法");
        }
        if(method.equals("delete")){
            req.getSession().setAttribute("msg","执行了delete的方法");
        }

        //2.调用业务层

        //3.试图转发或者重定向
        req.getRequestDispatcher("/WEB-INF/jsp/test.jsp").forward(req,resp);

        //加上forward是为了把参数带上，防止 后面需要使用的地方

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
       doGet(req, resp);
    }
}
